import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver=webdriver.Firefox()
driver.get('http://10.59.9.12:7001/')
driver.maximize_window()
time.sleep(3)

# ①　登录成功
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(3)
driver.find_element(By.NAME,'username').send_keys('13811033962')
time.sleep(3)
driver.find_element(By.NAME,'password').send_keys('123456')
time.sleep(10)
driver.find_element(By.XPATH,'//*[@id="theForm"]/div[5]/a').click()
time.sleep(3)
#切换窗口
driver.switch_to.window(driver.window_handles[-1])
time.sleep(5)
# ②　商品搜索
driver.find_element(By.CLASS_NAME,'search-input').send_keys('音乐耳机')
time.sleep(3)
driver.find_element(By.CLASS_NAME,'search-input-btn').click()
time.sleep(3)
# ③　首页商品列表
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
time.sleep(3)
# ④　商品详情
driver.find_element(By.XPATH,'/html/body/div[8]/div[2]/div[2]/div[2]/ul/li[2]/div[1]/a/img').click()
time.sleep(5)
# ⑤　加入购物车
driver.find_element(By.ID,'add-cart').click()
# driver.find_element(By.LINK_TEXT('加入购物车')).click()
time.sleep(5)
# ⑥　确认订单
driver.find_element(By.XPATH,'//*[@id="buy-cart"]').click()
time.sleep(3)
# ⑦　创建订单并支付
driver.find_element(By.ID,'address-801').click()
time.sleep(3)
driver.find_element(By.CSS_SELECTOR,'#order-button').click()
time.sleep(3)
# #获取所有窗口
# hq=driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/p/a')
# time.sleep(3)
# #打印所有窗口
# print(hq)
#退出浏览器
driver.close()